package easystudy.admin;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import easystudy.dao.MemberDao;
import easystudy.dto.Member;

@Controller
public class MemberUpdateController {
	
	private MemberDao memberDao;
	
	public void setMemberDao(MemberDao memberDao){
		this.memberDao = memberDao;
	}
	
	@RequestMapping(value="/ad_member_update.ad", method=RequestMethod.GET)
	protected ModelAndView doSendUpdateForm(@RequestParam("member_num")int member_num){
		return new ModelAndView("member_update","member",memberDao.getMemberDetail(member_num));
	}
	
	@RequestMapping(value="/ad_member_update.ad", method=RequestMethod.POST)
	protected ModelAndView doUpdateProcess(@ModelAttribute Member member){
		memberDao.updateMember(member);
		memberDao.deleteMember(member.getNum(), member.getState());
		String link="member_detail.ad?member_num="+member.getNum()+"&page=1";
		return new ModelAndView(new RedirectView(link));
	}

}
